<?php
require_once('includes/config.php');
require_once('includes/commonfunctions.php');

$metaTitle = 'Indian Mobile Price';
$metaDescription = '';
$metaKeywords = '';

//-------------------------------------------------------------------------------------------------------------//

$returnTo = $_GET['returnTo'];

if(isset($_POST['submit'])) {
      //echo '<pre>';var_dump($_POST);exit;
      $username = $_POST['username'];
      $password = $_POST['password'];
      
      $isLoggedIn = loginUser($username, $password);
      
      if($isLoggedIn) {
	    $returnTo = isset($returnTo) && !empty($returnTo) ? $returnTo : 'index.php';
	    
	    header('location: '.$returnTo);
	    exit;
      }
      else {
	    $errorMsg = 'Invalid username or password. Try again.';
      }
}
//-------------------------------------------------------------------------------------------------------------//
include('includes/header.php');

?>
</head>
<body>

<div id="main_container">
	
<?php include('includes/toppart.php')?>       
      
<?php include('includes/leftpart.php')?>
   
   
  <div class="center_content">
   	<div class="center_title_bar">Login</div>
    
    	<div class="prod_box_big">
            <div class="top_prod_box_big"></div>
            <div class="center_prod_box_big">            
		  
		  <form name="loginForm" id="loginForm" action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
		  <div class="contact_form">
			<?php if(isset($errorMsg)) { ?>
			<div class="red"><?=$errorMsg?></div>
			<?php } ?>
                    <div class="form_row">
                    <label class="contact"><strong>Username:</strong></label>
                    <input type="text" name="username" id="username" class="contact_input" />
                    </div>  

                    <div class="form_row">
                    <label class="contact"><strong>Password:</strong></label>
                    <input type="password" name="password" id="password" class="contact_input" />
                    </div>

                    <div class="form_row">
		  <input type="hidden" name="returnTo" id="returnTo" value="<?=$returnTo?>" />
		    <input type="submit" name="submit" id="submit" class="right" value="Login" />
                    </div>      
                    
		  </div> 
		  </form>
                                     
            </div>
            <div class="bottom_prod_box_big"></div>                                
        </div>
   </div><!-- end of center content -->
   
</div><!-- end of main content -->
   
   <?php include('includes/bottompart.php')?>
</div>
<!-- end of main_container -->
</body>
</html>